# -*- coding:utf-8 -*-

import models
from Company import companyTypeDisplayTable

actionTypeDisplayTable = {
    models.Action.OPERATOR_CREATE : u'创建',
    models.Action.OPERATOR_PUSH : u'向后推送',
    models.Action.OPERATOR_RECEIVE : u'接受',
    models.Action.OPERATOR_UNDO : u'退回',
    models.Action.OPERATOR_RETURN : u'撤销',
    models.Action.OPERATOR_MODIFY : u'修改'
}

def getFormatActions(caseId):
    actions = models.Action.caseActionsWithUserInfo(caseId)
    userIds = [action.user_id for action in actions]
    userInfos =  models.Company.getCompanyByUserIds(userIds)
    userInfos = {info.user_id : info for info in userInfos}
    for action in actions:
        info = userInfos[action.user_id]
        action.action_type = actionTypeDisplayTable[action.action_type]
        action.operate_time = str(action.operate_time)
        if models.User.TYPE_CHIEF == info.user_type:
            action.user_type = u'段长'
        else:
            action.user_type = companyTypeDisplayTable[info.company_type]
    return actions
